package gov.pbc.nn.kjgl.item.project.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import gov.pbc.nn.kjgl.item.dao.ProjectItemDao;
import gov.pbc.nn.kjgl.item.entity.ProjectItem;
import gov.pbc.nn.kjgl.item.template.entity.ItemApproval;
import gov.pbc.nn.kjgl.item.template.service.ICompleteTaskByCzService;
import gov.pbc.nn.uflo.entity.Opinion;

@Component("rjCompleteTaskByCzService")
public class RjCompleteTaskByCzService implements ICompleteTaskByCzService {
	@Autowired
	private ProjectItemDao projectItemDao;

	@Override
	public boolean support(String className) {
		if (className.equals(ProjectItem.class.getName())) {
			return true;
		} else {
			return false;
		}
	}
	@Override
	public void execute(Opinion opinion) throws Exception {
		ItemApproval itemApproval = projectItemDao.get(opinion.getBusKey(), ItemApproval.class);
		ProjectItem projectItem = projectItemDao.get(itemApproval.getBusKey(), ProjectItem.class);
		if(projectItemDao.ajaxCheckKj(projectItem.getCreateUser())){
			projectItem.setApplyDeptOpinion(opinion.getOpinion());
		}else{
			projectItem.setDevDeptOpinion(opinion.getOpinion());
		}
		this.projectItemDao.update(projectItem);
	}
}
